package com.fanrenqiji.modules.sys.service.impl;

import com.fanrenqiji.common.persistence.Page;
import com.fanrenqiji.common.service.BaseCommonService;
import com.fanrenqiji.modules.sys.dao.ConfigDao;
import com.fanrenqiji.modules.sys.entity.Config;
import com.fanrenqiji.modules.sys.service.ConfigService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lijian E-mail:ljz0721cx@163.com
 * @version 创建时间：2015年2月28日 下午2:43:51
 * @description
 */
@Service
@Transactional(readOnly = true)
public class ConfigCommonServiceImpl extends BaseCommonService implements ConfigService {

	@Autowired
	private ConfigDao configDao;

	@Override
	public Config getConfig(Long id) {
		return configDao.findOne(id);
	}

	@Override
	public Page<Config> findConfigByPage(Page<Config> page, Config config) {
		DetachedCriteria dc = configDao.createDetachedCriteria();
		
		if (StringUtils.isNotEmpty(config.getName())) {
			dc.add(Restrictions.like("name", "%" + config.getName() + "%"));
		}
		dc.add(Restrictions.eq(Config.DEL_FLAG, Config.DEL_FLAG_NORMAL));
		dc.addOrder(Order.asc("createDate"));
		return configDao.find(page, dc);
	}


	
	@Override
	@Transactional(readOnly = false)
	public void save(Config config) {
		configDao.save(config);
	}

	@Transactional(readOnly = false)
	public void delete(Long id) {
		configDao.deleteById(id);
		
	}

}
